class People {
    name?: string;
    age: number;
    addr:string;
    constructor(_name:string,_age:number,_addr:string){
        // this指向创建实例的对象
        this.name = _name
        this.age = _age
        this.addr = _addr
    }
    doEat(){}
    doStep(){}
}


let p = new People("wangwu",23,'123')
p.doEat()

// 静态方法的使用
class DateUtil {
    static formatDate(){}
}
DateUtil.formatDate

// 单件(例)模式--比较常见---指的是一个类只允许外部获取到唯一的一个实例对象
// 有两种方式---方式1
// 单间模式
class DateUtil2 {
    static dateUtil1= new DateUtil2()
    private constructor(){
        console.log("创建对象..."); // 会优先执行这里的代码，再执行外面的代码
    }
    // static formatDate(){}
    // static diffDateByDay(){}
    // static diffDataByHour(){}
    // static timeConversion(restTime: number){}

    formatDate(){
        console.log("formatDate");
    }
    diffDateByDay(){}
    diffDataByHour(){}
    timeConversion(restTime: number){}

}
// 我们的类不允许外面出现两个类例如下
// let dateUtil = new DateUtil2()
// let dateUtil2 = new DateUtil2()

const dateUtil1=DateUtil2.dateUtil1
const dateUtil2=DateUtil2.dateUtil1
console.log(dateUtil1 === dateUtil2);
console.log(dateUtil1 === dateUtil2);// 这是重复的代码但是不会重复执行
console.log(dateUtil1 === dateUtil2);
dateUtil1.formatDate()
dateUtil2.formatDate()

// 方式2--静态方法

export default class DateUtil3 {
    static formatDate(){
        console.log('formatDate3')
    }
    static diffDateByDay(){}
    static diffDateBy(){}
    static timeCoversion(){}
}
DateUtil3.formatDate()

// 方法3

export class DateUtil4 {
    static dateUtil:DateUtil4
    static getInstance(){
        if(!this.dateUtil){
            this.dateUtil=new DateUtil4();
        }
        return this.dateUtil
    }

    private constructor(){
        console.log('创建对象2');
    }
    formatDate(){
        console.log('formatDate');
    }
    diffDateByDay(){}
    diffDateHour(){}
    timeConversion(restTime: number){}
}

const dateUtil5= DateUtil4.getInstance();
const dateUtil6= DateUtil4.getInstance();

console.log(dateUtil5 === dateUtil6)

// export {}